<?php


namespace Core\Kernel;


use Core\HttpKernel;

class Kernel implements \Core\Kernel
{
    private static $_instance;
    public function __construct()
    {

    }

    public static function instance() {
        if(empty(self::$_instance)) {
            self::$_instance = new static();
        }
        return self::$_instance;
    }


    public function input() {

    }

    public function output($response) {

    }


    public function handlerList($request) {
        foreach($this->handlerList() as $handler) {
           $handler->execute($request);
        }
        return $request;
    }

    public function filterList($response) {
        foreach($this->loadFilters() as $filter) {
            $repsone = $filter->execute($response);
        }
        return $response;
    }

    public function loadHandler() {
        return array_merge($this->coreHandler,$this->handlers);
    }

    public function loadFilters() {
        return array_merge($this->coreFilter,$this->filters);
    }

    public function run($request,$response) {

    }

    public function request() {
        $input = $this->input();
        return new Http\Request($input);
    }

    public function response() {
        return $this->output(new Http\Response());
    }

    public function coreHandler() {
        return [
            array($this,'LogicHandler')
        ];
    }
    
    public function coreFilter() {
        return [
            array($this,'ResponseCache')
        ];
    }

    public function Handler($request,$response) {
        $response = $this->handlerList($request);
        $response = $this->filterList($response);
        return $response->send();
    }
}